package serviceImpl

import (
	"context"
	"goMicro/day05/server/services"
	"strconv"
	"time"
)

//测试方法
func newProd(id int32, pname string) *services.ProdModel {
	return &services.ProdModel{ProdID: id, ProdName: pname}
}

type ProdService struct{}

func (*ProdService) GetProdList(ctx context.Context, in *services.ProdRequest, resp *services.ProdListResponse) error {
	time.Sleep(time.Second * 3) //测试熔断使用
	models := make([]*services.ProdModel, 0)
	var i int32
	for i = 0; i < in.Size; i++ {
		models = append(models, newProd(100+i, "商品"+strconv.Itoa(100+int(i))))
	}
	resp.Data = models
	return nil
}

func (*ProdService) GetProdDetail(ctx context.Context, req *services.ProdRequest, resp *services.ProdDetailResponse) error {
	time.Sleep(time.Second * 3) //测试熔断使用
	resp.Data = newProd(req.ProdId, "测试商品名称"+strconv.Itoa(int(req.ProdId)))
	return nil
}
